<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>临时交易车辆信息</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <link href="<%=basepath%>css/index.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/parking.css" rel="stylesheet" type="text/css">
    <script src="<%=basepath%>js/jquery-1.8.3.min.js"></script>
    <script src="<%=basepath%>js/layer/layer.js"></script>
    <script type="text/javascript" src="<%=basepath%>js/ajax-pushlet-client.js"></script>
</head>
<body>
    <div class="viewport">
    <div id="buyer"></div>
    <form method="post" id="myForm" action="/wape-web/api/core/centerService">
        <input type="hidden" name="inRecordKey" value="${cp.inRecordKey}" />
        <div class="header">
            <div class="header-1">
                <a href="javascript:void(0)" id="join" class="header-2">
                    <span id="account" class="account">${empty user.realName ? '您还未登录哦！' : user.realName}</span>&nbsp;&nbsp;<span id="compNickName" class="compNickName">${user.companyNickName}</span>&nbsp;&nbsp;<span id="deptName" class="deptName">${user.departmentName}</span>
                </a>
                <c:set var="rightIn" value=",200801,"></c:set>
                <c:if test="${(fn:indexOf(rightIn, user.departmentId) != -1)}">
                    <input type="hidden" name="serviceCode" value="MMZS127" />
                    <span class="span-p"><input type="submit" value="确认修改" class="submit-1"></span>
                </c:if>
                <span class="span-num"></span>
            </div>
        </div>
        <div class="blank"></div>
        <div class="content m-top">
            <div class="blank"></div>
            <div class="content2-1">
                <div class="content2-1-1">
	            <input type="hidden" name="storeId" value="${cp.storeId}" />
	            <input type="hidden" name="storeName" value="${cp.storeName}" />
	            <input type="hidden" name="sonStoreId" value="${cp.sonStoreId}" />
	            <input type="hidden" name="sonStoreName" value="${cp.sonStoreName}" />
                    <table>
                        <tr>
                            <td class="td-1">棚位分区：</td>
                            <td class="td-2">${cp.storeName}</td>
                            <td class="td-3">编号：</td>
                            <td class="td-4">${cp.sonStoreName}</td>
                        </tr>
                    </table>
                </div>
            </div>
            <c:if test="${cp.parkState eq '1' || cp.parkState eq '2'}">
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">调度员：</td>
                            <td class="td-2">${cp.dispatcherName}</td>
                            <td class="td-3">调度时间：</td>
                            <td class="td-4">${cp.dispatcherDay } ${cp.dispatcherTime }</td>
                        </tr>
                    </table>
                </div>
            </div>
            </c:if>
            <c:if test="${cp.parkState eq '2'}">
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">收费员：</td>
                            <td class="td-2">${cp.chargerName_30 }</td>
                            <td class="td-3">收费时间：</td>
                            <td class="td-4">${cp.chargesDay_30 } ${cp.chargesTime_30 }</td>
                        </tr>
                    </table>
                </div>
            </div>
            </c:if>
            <div class="content2-2"><div class="content2-2-1"><span class="span-1">车辆进场情况：</span></div></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">进场单号：</td>
                            <td>
                                <input type="text" class="input-2"  value="${cp.inRecordNum }" name="inRecordNum" id="inRecordNum" placeholder=" * 必填项">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">车牌号码：</td>
                            <td>
                                <input type="text" class="input-2" value="${cp.plateNum }" name="plateNum" id="plateNum" placeholder=" * 必填项">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="hr"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">车辆类型：</td>
                            <td class="td-2">
                                    <select name="carType" id="carType">
                                        <c:if test="${cp.carType == '拖头冷柜车' }">
                                            <option value="拖头冷柜车" selected="selected">-拖头冷柜车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '拖头冷柜车' }">
                                            <option value="拖头冷柜车" >-拖头冷柜车-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.carType == '拖头平板车' }">
                                            <option value="拖头平板车" selected="selected">-拖头平板车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '拖头平板车' }">
                                            <option value="拖头平板车" >-拖头平板车-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.carType == '栏板式货车' }">
                                            <option value="栏板式货车" selected="selected">-栏板式货车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '栏板式货车' }">
                                            <option value="栏板式货车" >-栏板式货车-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.carType == '厢式冷藏车' }">
                                            <option value="厢式冷藏车" selected="selected">-厢式冷藏车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '厢式冷藏车' }">
                                            <option value="厢式冷藏车" >-厢式冷藏车-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.carType == '厢式货车' }">
                                            <option value="厢式货车" selected="selected">-厢式货车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '厢式货车' }">
                                            <option value="厢式货车" >-厢式货车-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.carType == '三轮车' }">
                                            <option value="三轮车" selected="selected">-三轮车-</option>
                                        </c:if>
                                        <c:if test="${cp.carType != '三轮车' }">
                                            <option value="三轮车" >-三轮车-</option>
                                        </c:if>
                                    </select>
                            </td>
                            <td class="td-3">吨位：</td>
                            <td class="td-4">
                                    <select name="weightType" id="weightType">
                                        <c:if test="${cp.weightType == '40吨及以上' }">
                                            <option value="40吨及以上" selected="selected">-40吨及以上-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '40吨及以上' }">
                                            <option value="40吨及以上" >-40吨及以上-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '30~40吨' }">
                                            <option value="30~40吨" selected="selected">-30~40吨-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '30~40吨' }">
                                            <option value="30~40吨" >-30~40吨-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '20~30吨' }">
                                            <option value="20~30吨" selected="selected">-20~30吨-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '20~30吨' }">
                                            <option value="20~30吨" >-20~30吨-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '10~20吨' }">
                                            <option value="10~20吨" selected="selected">-10~20吨-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '10~20吨' }">
                                            <option value="10~20吨" >-10~20吨-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '5~10吨' }">
                                            <option value="5~10吨" selected="selected">-5~10吨-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '5~10吨' }">
                                            <option value="5~10吨" >-5~10吨-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '3~5吨' }">
                                            <option value="3~5吨" selected="selected">-3~5吨-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '3~5吨' }">
                                            <option value="3~5吨" >-3~5吨-</option>
                                        </c:if>
                                        
                                        <c:if test="${cp.weightType == '3吨以下' }">
                                            <option value="3吨以下" selected="selected">-3吨以下-</option>
                                        </c:if>
                                        <c:if test="${cp.weightType != '3吨以下' }">
                                            <option value="3吨以下" >-3吨以下-</option>
                                        </c:if>
                                    </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="content2-3"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">收费标准：</td>
                            <td class="td-3">
                                    <select name="rate" class="input-2 text-r" id="js-1">
                                        <c:if test="${cp.rate eq '20' }">
                                            <option value="20" selected="selected">20</option>
                                        </c:if>
                                        <c:if test="${cp.rate ne '20' }">
                                            <option value="20" >20</option>
                                        </c:if>
                                        <c:if test="${cp.rate eq '50' }">
                                            <option value="50" selected="selected">50</option>
                                        </c:if>
                                        <c:if test="${cp.rate ne '50' }">
                                            <option value="50" >50</option>
                                        </c:if>
                                    </select>
                            </td>
                            <td class="td-5">元/吨</td>
                            <td class="td-3">实际重量：</td>
                            <td class="td-4">
                                <input type="text" class="input-2 text-r" value="${cp.count }" name="count" placeholder=" * 必填项" id="js-2" onkeyup="value=(this.value.match(/^-?\d+\.?\d{0,3}$/)||[''])[0]">
                            </td>
                            <td class="td-6">吨</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="hr"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">应缴费用：</td>
                            <td class="td-2">
                                <input type="text" class="input-2 text-r" value="${cp.costs }" name="costs" value="0" readonly="readonly" id="js-3" onkeyup="value=value.replace(/[^\d.]/g,'')">
                            </td>
                            <td class="td-5">元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            <td class="td-3">优惠金额：</td>
                            <td class="td-4">
                                <input type="text" class="input-2 text-r" value="${cp.benefit }" name="benefit" value="0" id="js-4" onkeyup="value=(this.value.match(/^-?\d+\.?\d{0,2}$/)||[''])[0]">
                            </td>
                            <td class="td-6">元</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="hr"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1">实缴费用：</td>
                            <td class="td-2">
                                <input type="text" class="input-2 text-r" value="${cp.payment }" name='payment' value="0" readonly="readonly" id="js-5" >
                            </td>
                            <td class="td-5">元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            <td class="td-3"></td>
                            <td class="td-4">
                                <input type="text" class="input-2" disabled="disabled" style="border:none;">
                            </td>
                            <td class="td-6"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="content2-3"></div>
            <div class="blank"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1 bold">商品种类：</td>
                            <td class="td-2">
                                <input type="text" value="水果" class="input-2" value="${cp.goodsKingdom }" name="goodsKingdom" id="goodsKingdom" readonly="readonly">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="hr"></div>
            <div class="content2-1">
                <div class="content2-1-1">
                    <table>
                        <tr>
                            <td class="td-1 bold">商品名称：</td>
                            <td>
                                <input type="text" class="input-2 text-left" value="${cp.goodsInfo }" name="goodsInfo" id="goodsInfo" readonly="readonly">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="blank"></div>
                <input type="hidden" id="sonid" name="son">
                <div class="content2-1-2">
                    <ul>
                        <c:forEach var="item" items="${goods}">
                            <li class="son" onclick="addFurit(this)"><a href='javascript:void(0)'>${item.son}</a></li>
                        </c:forEach>
                        <li id="add-1"><a href="javascript:void(0)" class="a-add" id="add">✚</a></li>
                    </ul>
                </div>
        </div>
        <div class="space"></div>
    </form>
</div>
</body>
<script type="text/javascript">
    /*错误提示*/
    $(function(){
        var error = "${requestScope.returnMsg}";
        if(error != "" && error != "成功!"){
            layer.msg(error,{shadeClose:true,shade:0.1,time:2000});
        }
    });
    /*添加*/
    $(function(){
        $(".son").click(function(){
            $(this).toggleClass("good");
        });
    });
    function addFurit(a){
        var good = $(a).text();
        var gival = $("#goodsInfo").val();
        var idx = gival.indexOf(good);
        var adv = "," + good;
        var tv = (gival + adv);
        if(idx == -1){
            if(tv.indexOf(",") == 0){
                tv = tv.substring(1);
            }
            $("#goodsInfo").val(tv);
        }else{
            if(gival.indexOf(",") == 0){
                var va = gival.replace(good,"");
                if(va.indexOf(",") == 0){
                    va = va.substring(1);
                }
                $("#goodsInfo").val(va);
            }else{
                var va = gival.replace(adv,"");
                var va = va.replace(good,"");
                if(va.indexOf(",") == 0){
                    va = va.substring(1);
                }
                $("#goodsInfo").val(va);
            }

        }
    }
    
    /*计算*/
    $(function(){
        $("#js-2").keyup(function(){
            var s1 = $("#js-1").val();
            var s2 = $("#js-2").val();
            var s4 = $("#js-4").val();
            var s3 = Math.round(s1*s2*100)/100;
            $("#js-3").val(s3);
            var s5 = Math.floor(Number(s3)-Number(Math.round(s4)));
            $("#js-5").val(s5);
        });
        
        $("#js-4").keyup(function(){
            var s1 = $("#js-1").val();
            var s2 = $("#js-2").val();
            var s4 = $("#js-4").val();
            var s3 = Math.round(s1*s2*100)/100;
            $("#js-3").val(s3);
            var s5 = Math.floor(Number(s3)-Number(Math.round(s4)));
            if(s5 < 0) {
                layer.msg("优惠金额应小于应缴金额",{shadeClose:true,shade:0.1,time:2000});
                $("#js-4").val('0');
                s5 = s1*s2;
            }
            $("#js-5").val(s5);
        });
    });
    
    /*添加*/
    $(function(){
        $("#add").click(function(){
            layer.prompt({
                title: '请输入商品名称',
                formType: 0
            }, function(text){
                if(text != ""){
                    layer.load();
                    $.ajax({
                        type:"post",
                        url:"/wape-web/api/core/core/centerService",
                        data:{
                            serviceCode:"3000P02",
                            son:text
                        },
                        success:function(data){
                            var add = eval("("+data+")");
                            if(add.returnCode == "200"){
                                $("#add-1").before("<li class='son' onclick='addFurit(this)'><a href='javascript:void(0)'>"+text+"</a></li>");
                            }
                            else if(add.returnCode == "W2001"){
                                layer.msg("商品已存在",{shadeClose:true,shade:0.1,time:2000});
                            }
                            else{
                                layer.msg("添加失败!",{shadeClose:true,shade:0.1,time:2000});
                            }
                        }
                    });
                }
                layer.closeAll();
            });
        })
    });
    
    /*提交表单*/
    $("#myForm").submit(function(){
        var inRecordNum = $("#inRecordNum").val();
        var plateNum = $("#plateNum").val();
        var js1 = $("#js-1").val();
        var js2 = $("#js-2").val();
        var js3 = $("#js-3").val();
        var js4 = $("#js-4").val();
        var js5 = $("#js-5").val();
        var goodsInfo = $("#goodsInfo").val();
        if(inRecordNum == ""){
            layer.msg("请输入进场单号",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(plateNum == ""){
            layer.msg("请输入车牌号码",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(js1 == ""){
            layer.msg("收费标准为0",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(js2 == ""){
            layer.msg("请输入实际吨数",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(js3 == ""){
            layer.msg("应交费用为0",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(js4 == ""){
            layer.msg("请输入优惠金额",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(js5 == ""){
            layer.msg("实缴费用为0",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else if(goodsInfo == ""){
            layer.msg("请选择商品名称",{shadeClose:true,shade:0.1,time:2000});
            return false;
        }
        else{
            layer.load();
            setTimeout(function(){
                layer.closeAll();
                layer.msg("网络异常，请重新尝试！",{shadeClose:true,shade:0.1,time:2000});
            }, 30000);
        }
    });
</script>
<script type="text/javascript">

    var sonStoreId = '${cp.sonStoreId}';
    var parkState = '${cp.parkState}';
    var departmentId = '${user.departmentId}';
    var right = ',2001,200101,200102,200103,';
    if((parkState == '1' || parkState == '2') && right.indexOf(',' + departmentId + ',') != -1) {
        //初始化pushlet客户端
        PL._init();
        //设定运行时显示调试信息，不需要时，直接删掉即可
        PL.setDebug(false);
        //设定监听主题：/wape/updateCarLock, 与服务器端的主题完全一致
        PL.joinListen('/wape/updateCarLock');
        //接收到事件后，显示服务器信息
        function onData(event) {
            var _currSonStoreId = event.get("currSonStoreId");
            var _locked = event.get("locked");
            if(_locked == '1' && _currSonStoreId == sonStoreId) {
            	$('#moveCar').attr('href', 'javascript:;');
            	$('#moveCar').attr('style', 'background-color: grey; cursor: default;');
            } else {
                $('#moveCar').attr('href', '/wape-web/api/core/core/centerService?serviceCode=MMZS201&parkState=${cp.parkState }&sonStoreId=${cp.sonStoreId }');
                $('#moveCar').removeAttr('style');
            }
        }
        //p_publish('/wape/updateCarLock', 'hw', 'test message!');
    }
</script>
</html>


